package Gather.GatherExercise;

import java.util.ArrayList;

/**
 * ClassName:UserText
 * Package:Gather.UserObjectGather
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/18-1:01
 * @Version:v1.0
 */
public class UserText001 {
    public static void main(String[] args) {
        ArrayList<User> list = new ArrayList<>();
        //创建三个用户对象
        User u1 = new User("001", "zhangsan", "huawei");
        User u2 = new User("002", "lisi", "huawei");
        User u3 = new User("003", "wangwu", "huawei");
        //把用户对象添加到集合当中
        list.add(u1);
        list.add(u2);
        list.add(u3);

        boolean flag=contains(list,"001");
        System.out.println(flag);
    }

    //我要干什么----->根据id查找用户
    //做这个事情需要什么才能完成---->id  list
    //调用出是否需要方法的结果  返回
    public static boolean contains(ArrayList<User> list, String id){
        for (int i = 0; i < list.size(); i++) {
//            list.get(i).getId().equals(id);
            User u=list.get(i);
            String uid = u.getId();
            if(uid.equals(id)){
                //如果找到了直接返回ture
                return true;
            }
        }
        //当循环结束表示集合
        return false;
    }
}
